package com.fare.taluo.application.impl.plane;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.fare.taluo.application.plane.AnalyseService;
import com.fare.taluo.vo.core.PlaneInfo;

public class QueryPriceServiceImpl extends AnalyseService{

	@Override
	public List<String> analyse(Map<String, PlaneInfo> csairPriceMap,
			Map<String, PlaneInfo> qunarPriceMap) {
		return null;
	}

	public static String toJSON(List<PlaneInfo> resultList,String depDate,int total){
		String jsonStr = "{\"total\":\""+total+"\","+
						 "\"rows\":[";
		for(int i = 0; i < resultList.size(); i++){
			PlaneInfo planeInfo = resultList.get(i);
			if(StringUtils.isEmpty(planeInfo.getFromCity())||StringUtils.isEmpty(planeInfo.getToCity())) continue;
			String flightType = "去程";
			String agentName = "";
			if(!planeInfo.getFlightBatchDate().equals(depDate)){
				flightType = "回程";
			}
			if(planeInfo.getAgentInfos() != null&&planeInfo.getAgentInfos().size() != 0){
				agentName = planeInfo.getAgentInfos().get(0).getName();
			}
			if(planeInfo != null){
				jsonStr += String.format("{\"no\":\"%d\",\"flighttype\":\"%s\",\"origin\":\"%s\",\"arrival\":\"%s\",\"date\":\"%s\",\"aircompany\":\"%s\",\"flightno\":\"%s\",\"flight\":\"%s\",\"deptime\":\"%s\",\"arrtime\":\"%s\",\"price\":\"%s\",\"channelname\":\"%s\",\"agentname\":\"%s\"}"
							,i+1,flightType,planeInfo.getFromCity(),planeInfo.getToCity(),planeInfo.getFlightBatchDate(),planeInfo.getCarrierFullName(),planeInfo.getFlightId(),planeInfo.getType(),planeInfo.getFlightBatchStartTime(),planeInfo.getFlightBatchEndTime(),
							planeInfo.getLowprPrice(),planeInfo.getGrabChannel(),agentName);
				jsonStr += ",";
			}
		}	
		if(jsonStr.endsWith(","))
			jsonStr = jsonStr.substring(0, jsonStr.length()-1);
		jsonStr += "]}";
		return jsonStr;
	}

	@Override
	public Map<String, List<String>> assembleFusionChartXml(Map<String, List<String>> chartMap,
			String dateStr, String key, Map<String, PlaneInfo> infoMap) {
		return null;
	}
}
